{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "9f440ae8",
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import pandas as pd\n",
    "import scipy.stats\n",
    "from sklearn import linear_model\n",
    "from sklearn.linear_model import LogisticRegression\n",
    "import matplotlib.pyplot as plt\n",
    "from scipy.stats import expon\n",
    "from scipy.optimize import minimize, rosen, rosen_der, basinhopping\n",
    "import seaborn as sns"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "1441b8db",
   "metadata": {},
   "source": [
    "**Import Data**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "25f4c328",
   "metadata": {},
   "outputs": [],
   "source": [
    "data=pd.read_csv(\"Original Data/TwoPerson.csv\")\n",
    "noFeedback=data[data.Treatment==1]\n",
    "Feedback=data[data.Treatment==2]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "1db3d517",
   "metadata": {},
   "outputs": [],
   "source": [
    "f=plt.figure()\n",
    "f.set_figheight(8)\n",
    "f.set_figwidth(16)\n",
    "\n",
    "plt.subplots_adjust(left=None, bottom=None, right=None, top=None, wspace=.2, hspace=.5)\n",
    "\n",
    "#for num,number in enumerate([2,3,4,5,6,7,8,9,0]):  \n",
    "\n",
    "# rc('font', **{'family': 'serif', 'serif': ['Computer Modern']})\n",
    "# rc('text', usetex=True)\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "num=0\n",
    "    \n",
    "for number in [2,6,0]:  \n",
    "    D=[]\n",
    "    S=[]\n",
    "    for i in noFeedback[(noFeedback.DecisionNumber%10==number)].index.values:\n",
    "        score=noFeedback[(noFeedback.index==i)].MyCurrentBest.values[0]\n",
    "        S.append(score)\n",
    "        D.append(noFeedback[(noFeedback.index==i)].Decision.values[0])\n",
    "\n",
    "    D=np.array(D)\n",
    "    S=np.array(S)\n",
    "\n",
    "    data=pd.DataFrame()\n",
    "    data[\"Score\"]=S\n",
    "    data[\"Draw\"]=D\n",
    "    \n",
    "    num=num+1\n",
    "    \n",
    "    plt.subplot(2,3,num)\n",
    "    sns.regplot(x='Score', y='Draw', data=data, logistic=True,label=\"Leader\", color=\"black\")\n",
    "    if number==0:\n",
    "        number=10\n",
    "    plt.title(r\"$\\mathrm{Period\\;%s}$\"%(number),size=14)\n",
    "    if number==2:\n",
    "        plt.ylabel(r\"$\\mathrm{Draw\\;Rate}$\", labelpad=12,size=14)\n",
    "    elif number!=2:\n",
    "        plt.yticks([0,.2,.4,.6,.8,1],['' for i in range(6)])\n",
    "        plt.ylabel(\"\", labelpad=12)\n",
    "    plt.xlabel(r\"$\\mathrm{Score}$\",labelpad=12,size=14)\n",
    "    #plt.legend(loc=1)\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "for number in [2,6,0]:  \n",
    "    FD=[]\n",
    "    LD=[]\n",
    "    S=[]\n",
    "    for i in Feedback[(Feedback.CurrentBest>0)&(Feedback.DecisionNumber%10==number)].index.values:\n",
    "        score=Feedback[(Feedback.index==i)].CurrentBest.values[0]\n",
    "        S.append(score)\n",
    "        other=Feedback[(Feedback.index==i)].OtherSubjectID.values[0]\n",
    "        decisionNumber=Feedback[(Feedback.index==i)].DecisionNumber.values[0]\n",
    "        #print(other,decisionNumber)\n",
    "        otherDecision=Feedback[(Feedback.DecisionNumber==decisionNumber)&(Feedback.SubjectID==other)].Decision.values[0]\n",
    "        if len(Feedback.loc[(Feedback.index==i)&(Feedback.MyCurrentBest==Feedback.CurrentBest)])==1:\n",
    "            LD.append(Feedback[(Feedback.index==i)].Decision.values[0])\n",
    "            FD.append(otherDecision)\n",
    "        elif len(Feedback.loc[(Feedback.index==i)&(Feedback.MyCurrentBest<Feedback.CurrentBest)])==1:\n",
    "            LD.append(otherDecision)\n",
    "            FD.append(Feedback[(Feedback.index==i)].Decision.values[0])\n",
    "\n",
    "    LD=np.array(LD)\n",
    "    FD=np.array(FD)\n",
    "    S=np.array(S)\n",
    "\n",
    "    data=pd.DataFrame()\n",
    "    data[\"Score\"]=S\n",
    "    data[\"Leader\"]=LD\n",
    "    data[\"Follower\"]=FD\n",
    "\n",
    "    num=num+1\n",
    "    \n",
    "    plt.subplot(2,3,num)\n",
    "    sns.regplot(x='Score', y='Leader', data=data, logistic=True,label=\"Leader\", color=\"black\")\n",
    "    sns.regplot(x='Score', y='Follower', data=data, logistic=True, label=\"Follower\",color=\"grey\",line_kws={'linestyle':'--'})\n",
    "    if number==0:\n",
    "        number=10\n",
    "    plt.title(r\"$\\mathrm{Period\\;%s}$\"%(number),size=14)\n",
    "    if number==2:\n",
    "        plt.ylabel(r\"$\\mathrm{Draw\\;Rate}$\", labelpad=12,size=14)\n",
    "    elif number!=2:\n",
    "        plt.yticks([0,.2,.4,.6,.8,1],['' for i in range(6)])\n",
    "        plt.ylabel(\"\", labelpad=12)\n",
    "    plt.xlabel(r\"$\\mathrm{Maximum\\;Score}$\",labelpad=12,size=14)\n",
    "    #plt.legend(loc=1)\n",
    "\n",
    "plt.savefig('figure5-bw.pdf')  \n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "3489ad44",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
